package com.th3t.enhance.jmx;
import java.lang.management.ManagementFactory;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import com.sun.jdmk.comm.HtmlAdaptorServer;

public class Main {
	/**
	 * @param args
	 * @throws NullPointerException
	 * @throws MalformedObjectNameException
	 * @throws NotCompliantMBeanException
	 * @throws MBeanRegistrationException
	 * @throws InstanceAlreadyExistsException
	 */
	public static void main(String[] args) 
			throws InstanceAlreadyExistsException, 
			MBeanRegistrationException, 
			NotCompliantMBeanException, 
			MalformedObjectNameException, 
			NullPointerException{
		//获得MBeanServer实例
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		//创建MBean
		LightMBean controller = new Light();
		//将MBean注册到MBeanServer中
		mbs.registerMBean(controller, new ObjectName("com.th3t.enhance.jmx:name=Light"));
		
		//创建适配器，用于能够通过浏览器访问MBean
		HtmlAdaptorServer adapter = new HtmlAdaptorServer();
		adapter.setPort(9797);
		mbs.registerMBean(adapter, new ObjectName("com.th3t.enhance.jmx:name=htmladapter,port=9797"));
		adapter.start();
		
		System.out.println("running...");
	}
}
